home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / REFERENC / TPR / SOURCE.EXE / ASPECTR.PAS next >
Pascal/Delphi Source File  |  1992-08-16  |  2KB  |  70 lines

  1. { ASPECTR.PAS }
  2. program AspectRatio;
  3. { Demonstrates the effect of varying the aspect ratio
  4.   on circle drawing. Increasing Xasp results in an
  5.   increasingly elliptical circle, in the Y axis.
  6.   Decreasing Xasp or increasing Yasp produces a
  7.   increasing ellipse in the horizontal direction.
  8. }
  9. uses
  10.   Crt, Graph;
  11.  
  12. var
  13.   { Parameters to InitGraph }
  14.   GraphDriver : Integer;
  15.   GraphError  : Integer;
  16.   GraphMode   : Integer;
  17.   { X and Y aspect ratio values }
  18.   Xasp, Yasp  : Word;
  19.   { Used for display purposes }
  20.   XString,
  21.   YString     : String[20];
  22.  
  23. procedure ClearSection ( X1, Y1, X2, Y2 : Integer );
  24. begin
  25.   SetViewPort (X1, Y1, X2, Y2, ClipOff);
  26.   ClearViewPort;
  27.   SetViewPort (0, 0, GetMaxX, GetMaxY, ClipOn);
  28. end;
  29.  
  30. begin
  31.  
  32.   { Request autodetection of correct graphics driver }
  33.   GraphDriver := Detect;
  34.  
  35.   { Initialize graphics system; look for driver files
  36.     in specified directory }
  37.   InitGraph ( GraphDriver, GraphMode, 'F:\BP\BGI' );
  38.  
  39.   GraphError := GraphResult;
  40.   if GraphError <> grOk  then
  41.   begin
  42.     Writeln('Error occurred:', GraphErrorMsg(GraphError));
  43.     Halt(1);
  44.   end;
  45.  
  46.   { Display prompt line }
  47.   SetTextJustify ( LeftText, BottomText );
  48.   SetTextStyle ( DefaultFont, HorizDir, 1 );
  49.   OutTextXY ( 10, GetMaxY - 10, 'Press any key to stop.');
  50.  
  51.   SetTextJustify( LeftText, TopText );
  52.   GetAspectRatio ( Xasp, Yasp );
  53.   repeat
  54.     Yasp := Yasp - 25;
  55.     SetAspectRatio ( Xasp, Yasp );
  56.     Circle ( GetMaxX div 2, GetMaxY div 2, 75 );
  57.     Str( Xasp:5, XString );
  58.     Str( Yasp:5, YString );
  59.     { Clear out a section on the screen and ... }
  60.     ClearSection (10, 10, 10+TextWidth(XString+', '
  61.           +YString), 10+TextHeight(XString));
  62.     { Display current Xasp and Yasp values }
  63.     OutTextXY ( 10, 10, XString + ', ' + YString );
  64.   until KeyPressed;
  65.  
  66.  
  67.   CloseGraph;
  68.  
  69. end.
  70.